#!/usr/bin/make -f

# PER USO SOTTO WINDOWS:
#  - scaricare make.zip da http://s.schivo.googlepages.com/make.zip
#  - decomprimere l'eseguibile make.exe in una directory in %PATH%
#  - per "clean" e "veryclean" usare "cleanw" e "verycleanw"
#  - decommentare la riga seguente (solo se non funziona ugualmente):
#SHELL=cmd.exe


.PHONY : clean veryclean compiler

OCC = ocamlc
LEXER = ocamllex
PARSER = ocamlyacc
OCCFLAGS = -c -g
DEP = ocamldep


MLFILES := exceptions.ml syntaxtree.ml print_syntaxtree.ml parser.ml lexer.ml intermediate.ml declaration.ml semantic.ml expressions.ml print.ml commands.ml subroutines.ml target.ml main.ml
CMOFILES := $(MLFILES:.ml=.cmo)
DEPFILES := $(filter-out lexer.ml parser.ml, $(MLFILES))

all: compiler

compiler: $(CMOFILES)
	$(OCC) -g $(CMOFILES) -o compiler.exe 

%.cmo: %.ml
	$(OCC) $(OCCFLAGS) $< -o $@

parser.ml : parser.mli
	$(OCC) $(OCCFLAGS) $@ 

parser.mli: parser.mly
	$(PARSER) $< 
	$(OCC) $(OCCFLAGS) $@

lexer.ml:
	$(LEXER) lexer.mll

-include $(DEPFILES:.ml=.d)

%.d : %.ml
	$(DEP) $< > $@

clean:
	rm -f parser.mli parser.ml lexer.ml *.cmo *.cmi *.d *~
	rm -rf output/*
	rm -rf input/*~

veryclean: clean
	rm -f compiler.exe
	rm -f *.out
	
cleanw:
	del /f parser.mli parser.ml lexer.ml *.cmo *.cmi *.d
	del /f /s output\*.*

verycleanw: cleanw
	del /f compiler.exe
	del /f *.out
